///////////////////////////////////////////////////////////////
//
// FileName : kfilesearcher.cpp
// Creator : BingXi Li
// Date : 2009-07-15 17:22:58
// Comment :
//
///////////////////////////////////////////////////////////////

#include "global.h"
#include "kfilesearcher.h"

using namespace KCS0014;

KFileSearcher::KFileSearcher()
{
	m_hSearch = INVALID_HANDLE_VALUE;
	memset(&m_Result, 0, sizeof(m_Result));
}

KFileSearcher::~KFileSearcher()
{
}

bool KFileSearcher::SearchFirst(const char* pchPathName, unsigned int nPathNameLength)
{
	bool bResult =  false;
	char* pchPath = NULL;
	pchPath = new char[nPathNameLength + 1];
	PROCESS_ERROR(pchPath != NULL);
	memcpy(pchPath, pchPathName, nPathNameLength);
	pchPath[nPathNameLength] = '\0';
	m_hSearch = FindFirstFileA(pchPath, &m_Result);
	PROCESS_ERROR(m_hSearch != INVALID_HANDLE_VALUE);

	bResult = true;

_KCS0014_PROCESS_EXIT_LABEL:
	if (NULL != pchPath)
		delete[] pchPath;
	return bResult;
}

bool KFileSearcher::SearchNext()
{
	bool bResult =  false;

	PROCESS_ERROR(m_hSearch != INVALID_HANDLE_VALUE);
	bResult = FindNextFileA(m_hSearch, &m_Result) == TRUE;

_KCS0014_PROCESS_EXIT_LABEL:
	return bResult;
}

bool KFileSearcher::GetResult(PWIN32_FIND_DATA pResult)
{
	bool bResult =  false;

	memcpy(pResult, &m_Result, sizeof(m_Result));


	bResult = true;

_KCS0014_PROCESS_EXIT_LABEL:
	return bResult;
}